% Deep Learning with FCN
% display the lvsc-- Sunnybrook result
% author: Shengji He
% date: 2018/12/21


clear all

path ='E:\717-3Lab\LVModel\CardiacData\MICCAI2009\Sunnybrook_val_submission\SC-HF-I-6';

manual_path = fullfile(path,'contours-manual\IRCCI-expert\');

auto_path = fullfile(path,'contours-auto\FCN\');

dicom_path = fullfile(path,'DICOM\');

% dicom_dir = dir([dicom_path,'*.dcm']);
manual_dir = dir([manual_path,'*-icontour-manual.txt']);
for i = 1:length(manual_dir)
    icontour_manual_txt = fullfile(manual_path,manual_dir(i).name);
%     icontour_manual = fullfile(manual_path,[dicom_name(1:end-4),]
    dicom_name = fullfile(dicom_path,strrep(manual_dir(i).name,'-icontour-manual.txt','.dcm'));
    ocontour_manual_txt=fullfile(manual_path,strrep(manual_dir(i).name,'icontour','ocontour'));
    if ~exist(dicom_name,'file')
        disp(['DICOM: ',dicom_name,' not exist']);
        continue;
    end
    if ~exist(ocontour_manual_txt,'file')
%         disp(['DICOM: ',dicom_name,' not exist']);
        continue;
    end
        
    dcm = double(dicomread(dicom_name));    
    [manual_ix,manual_iy]=txtread(icontour_manual_txt);
    [manual_ox,manual_oy]=txtread(ocontour_manual_txt);
    
    icontour_auto_txt = fullfile(auto_path,strrep(manual_dir(i).name,'manual','auto'));
    ocontour_auto_txt = fullfile(auto_path,strrep(manual_dir(i).name,'-icontour-manual','-ocontour-auto'));
    
    [auto_ix,auto_iy]=txtread(icontour_auto_txt);
    auto_ix=[auto_ix;auto_ix(1)];
    auto_iy=[auto_iy;auto_iy(1)];
    
    [auto_ox,auto_oy]=txtread(ocontour_auto_txt);
    auto_ox=[auto_ox;auto_ox(1)];
    auto_oy=[auto_oy;auto_oy(1)];
    
    
    
    imshow(dcm,[])
    hold on
    plot(manual_ix,manual_iy,'-g');
    plot(manual_ox,manual_oy,'-g');
    plot(auto_ix,auto_iy,'-r');
    plot(auto_ox,auto_oy,'-r');
    hold off
    
end



function [x,y]=txtread(txtfile)
if ~exist(txtfile,'file')
    disp(['File:',txtfile,' not existed']);
    x=[];
    y=[];
    return
end
fileID = fopen(txtfile);
C = textscan(fileID,'%f %f');
fclose(fileID);
xy=cell2mat(C);
x=xy(:,1);
y=xy(:,2);
end
